

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Cheney">
  <meta name="keywords" content="Coding">
  
    <meta name="description" content="对于不同数据序列，我们都有多种方法来排序，合适的算法可以节约大量时间和空间的开销，如何判断最高效的方法尤为重要。">
<meta property="og:type" content="article">
<meta property="og:title" content="排序算法应用及对比">
<meta property="og:url" content="https://cheney822.gitee.io/2020/12/05/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%AE%9E%E9%AA%8C--%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95%E5%BA%94%E7%94%A8%E5%8F%8A%E5%AF%B9%E6%AF%94/index.html">
<meta property="og:site_name" content="Cheney blog">
<meta property="og:description" content="对于不同数据序列，我们都有多种方法来排序，合适的算法可以节约大量时间和空间的开销，如何判断最高效的方法尤为重要。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/8b5105a4585142ff9fb997a89d2dc90f.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/f261bde37afa471a989e548157c7e805.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/c0a2d20b64364fd89da10f8f076d3b3c.png">
<meta property="article:published_time" content="2020-12-05T05:14:00.000Z">
<meta property="article:modified_time" content="2022-04-05T13:14:28.251Z">
<meta property="article:author" content="Cheney">
<meta property="article:tag" content="排序">
<meta property="article:tag" content="堆">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://imgbed.cheney.cc/picgo/8b5105a4585142ff9fb997a89d2dc90f.png">
  
  
  <title>排序算法应用及对比 - Cheney blog</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"cheney822.gitee.io","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":1},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Cheney Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('https://imgbed.cheney.cc/Blog_config/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="排序算法应用及对比">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-05 13:14" pubdate>
        2020年12月5日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.3k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      17 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">排序算法应用及对比</h1>
            
            <div class="markdown-body">
              <h1 id="一、课程设计题目与要求"><a href="#一、课程设计题目与要求" class="headerlink" title="一、课程设计题目与要求"></a>一、课程设计题目与要求</h1><p>排序算法应用及对比<br>【基本要求】</p>
<ul>
<li>1、生成三组1000万个数，分别为随机数、基本正序(所有元素在正序的基础上整体左移2位)、逆序（用什么数据结构？如果数据量达到1亿，10亿怎么办？）；</li>
<li>2、实现快速排序（改进版），归并排序和堆排序的递归和非递归版本；</li>
<li>3、要求从三组1000万数据中查找前d个最大的数（d是输入参数） ，请用快排，堆排序，归并排序以及插入/冒泡排序算法对所有数据排序后再查找最大的d个数，比较不同排序算法以及递归和非递归算法的区别(运行时间)；</li>
<li>4、不需要对1000万数据整体排序，从三组1000万数据中查找前d个最大和最小的数，用什么数据结构？</li>
</ul>
<h1 id="二、需求分析"><a href="#二、需求分析" class="headerlink" title="二、需求分析"></a>二、需求分析</h1><p>对于不同数据序列，我们都有多种方法来排序，合适的算法可以节约大量时间和空间的开销，如何判断最高效的方法尤为重要。</p>
<p>程序通过对不同的随机和有序序列用快速排序（改进版），归并排序和堆排序的递归和非递归版本进行搜索。分析不同算法的运行时间，得到不同大小，不同顺序下最优的搜索方法。</p>
<p>对于题目中的不对1000万数据整体排序，从三组1000万数据中查找前d个最大和最小的数，<strong>解决方法：</strong>建一个大小为d的最小堆，先取出前d个数并构建小顶堆，然后遍历数据与小顶堆的堆顶相比，比堆顶小直接丢弃，比堆顶大则替换堆顶，并重新构建这个堆，遍历完所有1000万个数之后得到的最小堆里面便是最大的d个数。
 </p>
<h1 id="三、设计"><a href="#三、设计" class="headerlink" title="三、设计"></a>三、设计</h1><h2 id="3-1-设计思想"><a href="#3-1-设计思想" class="headerlink" title="3.1 设计思想"></a>3.1 设计思想</h2><h3 id="（1）数据结构设计"><a href="#（1）数据结构设计" class="headerlink" title="（1）数据结构设计"></a>（1）数据结构设计</h3><p>三个动态数组ABC大小为用户输入的大小，分别用来存储随机数、基本正序(所有元素在正序的基础上整体左移2位)、逆序序列。<br>六个T_x (x = a-&gt;f) 复制ABC中的一个后用来给几种算法做排序。</p>
<h3 id="（2）算法设计"><a href="#（2）算法设计" class="headerlink" title="（2）算法设计"></a>（2）算法设计</h3><p> <img src="https://imgbed.cheney.cc/picgo/8b5105a4585142ff9fb997a89d2dc90f.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>程序涉及到的搜索函数如上图所示。
 </p>
<h2 id="3-2-详细设计"><a href="#3-2-详细设计" class="headerlink" title="3.2 详细设计"></a>3.2 详细设计</h2><p>快速排序（改进版）（交换排序的一种）<br><strong>递归快排：</strong><br>改进方案：改进选取枢轴的方法，即每次选取数据集中的中位数做枢轴，（选取中位数的可以在 O(n)时间内完成）。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></div></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//返回中位数位置</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">GetMiddleValue</span><span class="hljs-params">(<span class="hljs-type">int</span> A[], <span class="hljs-type">int</span> low, <span class="hljs-type">int</span> high)</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-comment">//  int mid = low + (high - low) &gt;&gt; 1;</span><br>    <span class="hljs-type">int</span> mid = (high + low) / <span class="hljs-number">2</span>;<br><br>    <span class="hljs-type">int</span> y1 = A[low] &gt; A[mid] ? low : mid;<br>    <span class="hljs-type">int</span> y2 = A[low] &gt; A[high] ? low : high;<br>    <span class="hljs-type">int</span> y3 = A[mid] &gt; A[high] ? mid : high;<br><br>    <span class="hljs-keyword">if</span> (y1 == y2) <span class="hljs-keyword">return</span> y3;<br><br>    <span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> A[y1] &gt; A[y2] ? y2 : y1;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>快排的分割策略：第一步是通过将枢轴元与最后一个元素交换使得枢轴元离开要被分割的数据段；i 从第一个元素开始而 j 从倒数第二个元素开始。当 i 在 j 左边时，我们将 i 右移，移过那些小于枢轴元的元素，并将 j 左移，移过那些大于枢轴元的元素。当 i 和 j 停止时，i 指向的是大元素，j指向的是小元素。如果 i 在 j 左边，那么将这两个元素互换。 如果此时 i 和 j 已经交错即 i&gt;j所以不交换。此时把枢轴元与 i 所指的元素交换。</p>
<p>基于栈的非递归快排：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">FD_QuickSort</span><span class="hljs-params">(<span class="hljs-type">int</span> AA[], <span class="hljs-type">int</span> low, <span class="hljs-type">int</span> high)</span></span><br><span class="hljs-function"></span>&#123;<br>    stack&lt;<span class="hljs-type">int</span>&gt;x;<br>    stack&lt;<span class="hljs-type">int</span>&gt;y;<br>    x.<span class="hljs-built_in">push</span>(low);<br>    y.<span class="hljs-built_in">push</span>(high);<br>    <span class="hljs-type">int</span> Beg, End, k;<br><br>    <span class="hljs-keyword">while</span> (x.<span class="hljs-built_in">size</span>() != <span class="hljs-number">0</span>) &#123;<br>        Beg = x.<span class="hljs-built_in">top</span>();<br>        x.<span class="hljs-built_in">pop</span>();<br>        End = y.<span class="hljs-built_in">top</span>();<br>        y.<span class="hljs-built_in">pop</span>();<br><br>        k = <span class="hljs-built_in">partition</span>(AA, Beg, End);<br><br>        <span class="hljs-comment">//      PrintA(AA, N);</span><br><br>        <span class="hljs-keyword">if</span> (Beg &lt; k - <span class="hljs-number">1</span>)<br>        &#123;<br>            x.<span class="hljs-built_in">push</span>(Beg);<br>            y.<span class="hljs-built_in">push</span>(k - <span class="hljs-number">1</span>);<br>        &#125;<br>        <span class="hljs-keyword">if</span> (End &gt; k + <span class="hljs-number">1</span>)<br>        &#123;<br>            x.<span class="hljs-built_in">push</span>(k + <span class="hljs-number">1</span>);<br>            y.<span class="hljs-built_in">push</span>(End);<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>第一步、申请一个栈，存放排序数组的起始位置和终点位置。<br>第二步、将整个数组的起始位置s和终点位置e进栈<br>第三步、出栈数据，对出栈的数据进行排序，查找基准数据所在最终的位置 p。<br>第四步、判断起始位置s 是否小于基准位置p-1，如果小于则将起始位置和p-1为终点位置进栈<br>第五步、判断基准位置p+1 是否小于终点位置e，如果小于则将 p+1作为起始位置，e作为终点位置进栈<br>第六步、判断栈是否为空，如果不为空则重复第三步，否则退出操作。</p>
<p><strong>归并排序：</strong><br>基本思路就是将数组分成二组A，B，如果这二组组内的数据都是有序的，那么就可以很方便的将这二组数据进行排序。可以将A，B组各自再分成二组。依次类推，当分出来的小组只有一个数据时，可以认为这个小组组内已经达到了有序，然后再合并相邻的二个小组就可以了。这样通过先递归的分解数列，再合并数列就完成了归并排序。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//将有二个有序数列a[first...mid]和a[mid...last]合并。</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">mergearray</span><span class="hljs-params">(<span class="hljs-type">int</span> a[], <span class="hljs-type">int</span> first, <span class="hljs-type">int</span> mid, <span class="hljs-type">int</span> last, <span class="hljs-type">int</span> temp[])</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-type">int</span> i = first, j = mid + <span class="hljs-number">1</span>;<br>    <span class="hljs-type">int</span> m = mid, n = last;<br>    <span class="hljs-type">int</span> k = <span class="hljs-number">0</span>;<br><br>    <span class="hljs-keyword">while</span> (i &lt;= m &amp;&amp; j &lt;= n)<br>    &#123;<br>        <span class="hljs-keyword">if</span> (a[i] &lt; a[j])<br>            temp[k++] = a[i++];<br>        <span class="hljs-keyword">else</span><br>            temp[k++] = a[j++];<br>    &#125;<br><br>    <span class="hljs-keyword">while</span> (i &lt;= m)<br>        temp[k++] = a[i++];<br><br>    <span class="hljs-keyword">while</span> (j &lt;= n)<br>        temp[k++] = a[j++];<br><br>    <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; k; i++)<br>        a[first + i] = temp[i];<br>&#125;<br></code></pre></td></tr></table></figure>


<p>堆排序：（选择排序的一种）<br><strong>存储：</strong><br>一般都用数组来表示堆，i结点的父结点下标就为(i – 1) / 2。它的左右子结点下标分别为2 * i + 1和2 * i + 2。</p>
<p><strong>堆化数组：</strong><br>根据堆的性质, 只要保证部分有序即可, 即根节点大于左右节点的值. 将数组抽象为一个完全二叉树, 所以只要从最后一个非叶子节点向前遍历每一个节点即可. 如果当前节点比左右子树节点都大, 则已经是一个最大堆, 否则将当前节点与左右节点较大的一个交换, 并且交换过之后依然要递归的查看子节点是否满足堆的性质, 不满足再往下调整. 如此即可完成数组的堆化.<br>以下为非递归堆的调整代码</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//  从i节点开始调整,n为节点总数 从0开始计算 i节点的子节点为 2*i+1, 2*i+2</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">FD_AdjustHeap</span><span class="hljs-params">(<span class="hljs-type">int</span> a[], <span class="hljs-type">int</span> ii, <span class="hljs-type">int</span> n)</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-type">int</span>  temp = a[ii];<br>    <span class="hljs-type">int</span> L = <span class="hljs-number">2</span> * ii + <span class="hljs-number">1</span>;<br>    <span class="hljs-type">int</span> R = <span class="hljs-number">2</span> * ii + <span class="hljs-number">2</span>;<br><br>    <span class="hljs-keyword">while</span> (L &lt; n)<br>    &#123;<br>        <span class="hljs-keyword">if</span> (R &lt; n &amp;&amp; a[R] &gt; a[L]) <span class="hljs-comment">//在左右孩子中找最大的</span><br>            L++;<br><br>        <span class="hljs-keyword">if</span> (a[L] &lt;= temp)<br>            <span class="hljs-keyword">break</span>;<br><br>        a[ii] = a[L];     <span class="hljs-comment">//把较大的子结点往上移动,替换它的父结点</span><br>        ii = L;<br>        L = <span class="hljs-number">2</span> * ii + <span class="hljs-number">1</span>;<br>    &#125;<br>    a[ii] = temp;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>排序（删除）：</strong><br>为了便于重建堆，实际的操作是将最后一个数据的值赋给根结点，然后再从根结点开始进行一次从上向下的调整。调整时先在左右儿子结点中找最小的，如果父结点比这个最小的子结点还小说明不需要调整了，反之将父结点和它交换后再考虑后面的结点。相当于从根结点将一个数据的“下沉”过程。<br>//非递归堆排序</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">FD_HeapSort</span><span class="hljs-params">(<span class="hljs-type">int</span> a[], <span class="hljs-type">int</span> n)</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-built_in">FD_BuildHeap</span>(a, n);<br>    <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = n - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--)<br>    &#123;<br>        <span class="hljs-built_in">Swap</span>(a[i], a[<span class="hljs-number">0</span>]);<br>        <span class="hljs-built_in">FD_BuildHeap</span>(a, i);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h1 id="四、测试数据及测试结果："><a href="#四、测试数据及测试结果：" class="headerlink" title="四、测试数据及测试结果："></a>四、测试数据及测试结果：</h1><p>长度10000，查找个数10</p>
<p><img src="https://imgbed.cheney.cc/picgo/f261bde37afa471a989e548157c7e805.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>长度100000，查找个数10</p>
<p><img src="https://imgbed.cheney.cc/picgo/c0a2d20b64364fd89da10f8f076d3b3c.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E6%8E%92%E5%BA%8F/">排序</a>
                    
                      <a class="hover-with-bg" href="/tags/%E5%A0%86/">堆</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/12/06/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%AE%9E%E9%AA%8C--%E6%90%9C%E7%B4%A2%E6%95%88%E7%8E%87%E6%AF%94%E8%BE%83/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">搜索效率比较</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/04/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%AE%9E%E9%AA%8C--%E5%B8%A6%E7%8E%AF%E3%80%81%E7%9B%B8%E4%BA%A4%E9%93%BE%E8%A1%A8%E9%97%AE%E9%A2%98/">
                        <span class="hidden-mobile">带环、相交链表问题</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://cheney822.gitee.io/" target="_blank" rel="nofollow noopener"><span>备用网址</span></a> 
  </div>
  

  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        皖ICP备2022002876号-1
      </a>
    </span>
    
  </div>


  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
